{% from '_comment.html' import show_comments with context %}
{% macro comment_filed(form,comments) %}
    <div class=" panel panel-info">
        <div class="panel-heading">评论：</div>
        <div class="panel-body container-fluid">
            <form method="post">
                {{ form.csrf_token }}
                <div class="form-group form-inline">
                    {% if g.user.is_authenticated() %}
                        <label id="who">{{ g.user.nicename }}</label>
                        {{ form.name(value=g.user.nicename,style="display:none") }}
                    {% else %}
                        <label id="who">{{ form.name.label }}</label>
                        {{ form.name(class='form-control') }}
                        {% for error in form.errors.name %}
                            <span style="color: red;">{{ error }}</span>
                        {% endfor %}
                    {% endif %}
                </div>
                <div class="form-group">
                    {{ form.comment(class='form-control',rows='3',cols='20',id='comment') }}
                    {% for error in form.errors.comment %}
                        <span style="color: red;">{{ error }}</span>
                    {% endfor %}
                </div>
                {{ form.submit(class='btn btn-success') }}
            </form>
        </div>
        <ul class="list-group">
            <li class="list-group-item">
                {{ show_comments(comments) }}
            </li>
        </ul>
    </div>
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">回复</h4>
                </div>
                <div class="modal-body">
                    <form method="post" id="comment_form">
                        <div class="form-group form-inline">
                            {% if g.user.is_authenticated() %}
                                <label id="who">{{ g.user.nicename }}</label>
                                <input value="{{ g.user.nicename }}" style="display:none" name="name"/>
                                <input name="user_id" value="{{ g.user.id }}" style="display:none">
                            {% else %}
                                <label id="who">一个名字：</label>
                                <input class='form-control' name="name"/>
                            {% endif %}
                        </div>
                        <div class="form-group">
                            <input name="parent_id" id="parent_id" style="display:none">
                            <input name="article_id" value="0" style="display:none">
                            <textarea class='form-control' rows='3' cols='20' id='comment' name="comment"></textarea>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">放弃</button>
                    <button type="button" class="btn btn-primary" onclick="sub_comment();"> 提交</button>
                </div>
            </div>
        </div>
    </div>
{% endmacro %}